﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;
using Torch.WL.Entity.CleanChina;

namespace Torch.WL.Business
{
    public class WeiboProvider : BaseProvider<WeiboProvider.RequestDataInfo>, IDataProvider
    {
        public WeiboProvider(string _jsonInfo)
            : base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            message.data = ProcessResponseData();
            return message;
            
        }

        private List<ResponseDataInfo> ProcessResponseData()
        {
            //use postdata.data to process responseData
            if (postdata == null || postdata.data == null)
            {
                message.code = (int)MessageCodeType.WrongRequestPara;
                message.message = Utils.GetEnumDescription(MessageCodeType.WrongRequestPara);
                return null;
            }

            //use postdata.data to process responseData
            List<ResponseDataInfo> list = new List<ResponseDataInfo>();
            ResponseDataInfo responseData = new ResponseDataInfo();
           

            List<TbWeiboEntity> listWeibo = TbWeiboManager.Instance().GetWeiboList(postdata.data.lessthan_wbid, postdata.data.pagesize);

            listWeibo.ForEach(delegate(TbWeiboEntity entity)
            {
                list.Add(
                    new ResponseDataInfo() {wbid=entity.wbId,
                        weibo_submittime = entity.submitTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        weibo_content = entity.weibo,                    
                        images = entity.weibo_images
                    }
                    );
            });
            /*
            responseData.weibo_submittime = "2014-03-15 09:20";
            responseData.weibo_content = "微博的内容, 这是一段不算长的文字";
            responseData.images = new List<string>();
            list.Add(responseData);

            responseData.weibo_submittime = "2014-03-15 09:10";
            responseData.weibo_content = "微博的内容, 这是一段不算长的文字, 介绍性的文字";
            responseData.images = new List<string>();
            responseData.images.Add(ConfigHelper.GetConfigString("WebsiteImageUrl") + "loading_1.jpg");
            responseData.images.Add(ConfigHelper.GetConfigString("WebsiteImageUrl") + "loading_2.jpg");

            list.Add(responseData);
            */

            return list;

         
        }

        public class RequestDataInfo 
        {
            public int lessthan_wbid { get; set; }
            public int pagesize { get; set; }
        }

        public class ResponseDataInfo
        {
            public int wbid { get; set; }
            public string weibo_submittime { get; set; }
            public string weibo_content { get; set; }
            public List<string> images { get; set; }            

        }


    }
}
